package com.tmeone.erpone.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tmeone.erpone.entity.JsonResult;
import com.tmeone.erpone.entity.TSettlement;
import com.tmeone.erpone.service.ITSettlementService;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.web.bind.annotation.*;

@RestController
public class TSettlementController {

    @Autowired
    private ITSettlementService itSettlementService;
    //分页
    @RequestMapping("/settlements")
    public JsonResult pageProducts(@RequestParam(value = "current",required = false,defaultValue = "1") Integer current,
                                   @RequestParam(value = "pageSize",required = false,defaultValue = "5") Integer pageSize) {
        IPage<TSettlement> arg = new Page<>(current, pageSize);
        IPage<TSettlement> page=itSettlementService.pageTSettlement(arg);
        return new JsonResult(1,page);
    }
    //分页
    @GetMapping("settlement")
    public JsonResult pageSettlement(@RequestParam(value = "current",required = false,defaultValue = "1")Integer current,
                                     @RequestParam(value = "pageSize",required = false,defaultValue = "5")Integer pageSize
            ,String input1){
        Page<TSettlement> settlementPage = new Page<>(current,pageSize);
        return new  JsonResult(1,itSettlementService.getPageSettlement(settlementPage,input1));
    }

//通过发货单号查询
    @RequestMapping("/TSettlement/{shippingNum}")
    public JsonResult FunctionsIdsByRoleId(@PathVariable String shippingNum){
        return  new JsonResult(1,itSettlementService.TSettlementByNum(shippingNum));
    }

//更改
    @PutMapping("/settlement")
    public JsonResult updateProduct(@RequestBody TSettlement tSettlement){
        if (tSettlement.getSettlementStatus().equals("-1")){
            tSettlement.setSettlementStatus("1");
        }
        itSettlementService.updateById(tSettlement);
        return new JsonResult(1, tSettlement);
    }



    //结算
    @GetMapping("jiesuan")
    public JsonResult settlement(){
        return new JsonResult(1,itSettlementService.count(new QueryWrapper<TSettlement>().lambda().eq(TSettlement::getSettlementStatus,1)));
    }

    //未结算
    @GetMapping("nojiesuan")
    public JsonResult noSettlement(){
        return new JsonResult(1,itSettlementService.count(new QueryWrapper<TSettlement>().lambda().eq(TSettlement::getSettlementStatus,-1)));
    }

}

